//
//  PacketAlertView.m
//  PlayCatchGame
//
//  Created by 流言 on 2018/1/27.
//  Copyright © 2018年 清正. All rights reserved.
//

#import "PacketAlertView.h"

@interface PacketAlertView ()

@property (nonatomic, copy) ButtonBlock clickBlock;
/// 标题
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

@end

@implementation PacketAlertView

- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (void)setPacketType:(NSInteger)packetType {
    _packetType =packetType;
    if (packetType ==1) {
        self.title_bgImage_centerY.constant =45;
        self.button.hidden =NO;
        self.titleLabel.font =[UIFont systemFontOfSize:25];
        self.titleLabel.textColor =[UIColor whiteColor];
        [self.button setTitle:@"注册可领取" forState:UIControlStateNormal];
        [self.bottomBtn setTitle:@"点击注册" forState:UIControlStateNormal];
    } else if (packetType ==2) {
        self.title_bgImage_centerY.constant =60;
        self.button.hidden =YES;
        self.titleLabel.font =[UIFont boldSystemFontOfSize:40];
        self.titleLabel.textColor =[UIColor colorWithRed:1.00 green:0.93 blue:0.21 alpha:1.00];
        [self.button setTitle:@"" forState:UIControlStateNormal];
        [self.bottomBtn setTitle:@"确定" forState:UIControlStateNormal];
    }
}

- (void)setTitleString:(NSString *)titleString {
    NSAssert((self.packetType !=0), @"请在调用此方法前给 packetType 赋值");
    
    NSMutableAttributedString *attributedString =[[NSMutableAttributedString alloc]initWithString:titleString];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:10.0];
    paragraphStyle.alignment = NSTextAlignmentCenter;
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [titleString length])];
    if (self.packetType ==2) {
        if ([titleString containsString:@"恭喜您获得"]) {
            NSRange range =[titleString rangeOfString:@"恭喜您获得"];
            [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:range];
            [attributedString addAttribute:NSForegroundColorAttributeName value:self.titleLabel.textColor range:NSMakeRange(0, [titleString length])];
        }
    }
    self.titleLabel.attributedText = attributedString;
    
}

- (IBAction)buttonClick:(UIButton *)sender {
    if (self.clickBlock) {
        self.clickBlock(sender);
    }
}


- (void)viewButtonClickBlock:(ButtonBlock)newBlock {
    self.clickBlock = newBlock;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
